<template>
  <div>

      <el-form :inline="true" v-show="isSearchCollapse" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
            <!-- 搜索框-->
         <el-form-item prop="abcClass">
                <el-input v-model="name" disabled  clearable></el-input>
         </el-form-item>
         <el-form-item prop="accoCodeName">

               <el-date-picker
                value-format="yyyy-MM-dd"
                 v-model="searchForm.finalDate"
                 align="right"
                 type="date"
                 placeholder="选择日期"
                 >
               </el-date-picker>
                <!-- <el-input size="small" v-model="searchForm.accoCodeName" placeholder="领料用途" clearable></el-input> -->
         </el-form-item>
        <!-- <el-form-item prop="acctCodeName">
                <el-input size="small" v-model="searchForm.acctCodeName" placeholder="抛帐会计科目（借方）" clearable></el-input>
         </el-form-item>
         <el-form-item prop="amt">
                <el-input size="small" v-model="searchForm.amt" placeholder="金额" clearable></el-input>
         </el-form-item>
         <el-form-item prop="assignLocNo">
                <el-input size="small" v-model="searchForm.assignLocNo" placeholder="发科仓库" clearable></el-input>
         </el-form-item>
         <el-form-item prop="audEmpName">
                <el-input size="small" v-model="searchForm.audEmpName" placeholder="审核人" clearable></el-input>
         </el-form-item>
         <el-form-item prop="benifitCostCen">
                <el-input size="small" v-model="searchForm.benifitCostCen" placeholder="受益成本中心" clearable></el-input>
         </el-form-item>
         <el-form-item prop="bsCompId">
                <el-input size="small" v-model="searchForm.bsCompId" placeholder="关联方公司id" clearable></el-input>
         </el-form-item>
         <el-form-item prop="buyer">
                <el-input size="small" v-model="searchForm.buyer" placeholder="采购员" clearable></el-input>
         </el-form-item>
         <el-form-item prop="chnName">
                <el-input size="small" v-model="searchForm.chnName" placeholder="物资名称" clearable></el-input>
         </el-form-item> -->
          <el-form-item>
            <el-button type="primary" @click="refreshList()" size="small">查询</el-button>
            <!-- <el-button @click="resetSearch()" size="small">重置</el-button> -->
          </el-form-item>
      </el-form>
        <!-- 导入导出-->
      <el-form :inline="true" v-show="isImportCollapse"  class="query-form" ref="importForm">
         <el-form-item>
          <el-button type="default" @click="downloadTpl()" size="small">下载模板</el-button>
         </el-form-item>
         <el-form-item prop="loginName">
            <el-upload
              class="upload-demo"
              :action="`${this.$http.BASE_URL}/spareparts/material/sparepartsErpBank/import`"
              :on-success="uploadSuccess"
               :show-file-list="true">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只允许导入“xls”或“xlsx”格式文件！</div>
            </el-upload>
        </el-form-item>
      </el-form>
      <el-row>
        <el-button v-if="hasPermission('spareparts:material:sparepartsErpBank:add')" type="primary" size="small" icon="el-icon-plus" @click="add()">新建</el-button>
        <el-button v-if="hasPermission('spareparts:material:sparepartsErpBank:edit')" type="warning" size="small" icon="el-icon-edit-outline" @click="edit()"
         :disabled="dataListSelections.length != 1" plain>修改</el-button>
        <el-button v-if="hasPermission('spareparts:material:sparepartsErpBank:del')" type="danger"   size="small" icon="el-icon-delete" @click="del()"
                  :disabled="dataListSelections.length <= 0" plain>删除
        </el-button>
        <el-button-group class="pull-right">
            <el-button
              type="default"
              size="small"
              icon="el-icon-search"
              @click="isSearchCollapse = !isSearchCollapse, isImportCollapse=false">
            </el-button>
            <el-button v-if="hasPermission('spareparts:material:sparepartsErpBank:import')" type="default" size="small" icon="el-icon-upload2" title="导入" @click="isImportCollapse = !isImportCollapse, isSearchCollapse=false"></el-button>
            <el-button v-if="hasPermission('spareparts:material:sparepartsErpBank:export')" type="default" size="small" icon="el-icon-download" title="导出" @click="exportExcel()"></el-button>
            <el-button
              type="default"
              size="small"
              icon="el-icon-refresh"
              @click="refreshList">
            </el-button>
        </el-button-group>
      </el-row>
    <el-table
      :data="dataList.slice((this.pageNo - 1) * this.pageSize, (this.pageNo - 1) * this.pageSize + this.pageSize)"
      border
      size="medium"
      @selection-change="selectionChangeHandle"
      @sort-change="sortChangeHandle"
      v-loading="loading"
      class="table">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
    <el-table-column
        prop="abcClass"
        show-overflow-tooltip
        sortable="custom"
        label="ABC分类"
        width="140px">
            <template slot-scope="scope">
              <el-link  type="primary" :underline="false" v-if="hasPermission('spareparts:material:sparepartsErpBank:edit')" @click="edit(scope.row.id)">{{scope.row.abcClass}}</el-link>
              <el-link  type="primary" :underline="false" v-else-if="hasPermission('spareparts:material:sparepartsErpBank:view')"  @click="view(scope.row.id)">{{scope.row.abcClass}}</el-link>
              <span v-else>{{scope.row.abcClass}}</span>
            </template>
      </el-table-column>
    <el-table-column
        prop="accoCodeName"
        show-overflow-tooltip
        sortable="custom"
        label="领料用途"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="acctCodeName"
        show-overflow-tooltip
        sortable="custom"
        label="抛帐会计科目（借方）"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="amt"
        show-overflow-tooltip
        sortable="custom"
        label="金额"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="assignLocNo"
        show-overflow-tooltip
        sortable="custom"
        label="发科仓库"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="audEmpName"
        show-overflow-tooltip
        sortable="custom"
        label="审核人"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="benifitCostCen"
        show-overflow-tooltip
        sortable="custom"
        label="受益成本中心"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="bsCompId"
        show-overflow-tooltip
        sortable="custom"
        label="关联方公司id"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="buyer"
        show-overflow-tooltip
        sortable="custom"
        label="采购员"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="chnName"
        show-overflow-tooltip
        sortable="custom"
        label="物资名称"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="chnSpec"
        show-overflow-tooltip
        sortable="custom"
        label="规格型号"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="civiConNo"
        show-overflow-tooltip
        sortable="custom"
        label="工程合同"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="civiNo"
        show-overflow-tooltip
        sortable="custom"
        label="工程项目编号"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="className"
        show-overflow-tooltip
        sortable="custom"
        label="物资分类第一级"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="conDept"
        show-overflow-tooltip
        sortable="custom"
        label="施工单位"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="costCenter"
        show-overflow-tooltip
        sortable="custom"
        label="成本中心"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="deliver"
        show-overflow-tooltip
        sortable="custom"
        label="保管员"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="finalDate"
        show-overflow-tooltip
        sortable="custom"
        label="出库日期"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="isZhiFa"
        show-overflow-tooltip
        sortable="custom"
        label="是否直发现场"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="issueDate"
        show-overflow-tooltip
        sortable="custom"
        label="申请日期"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="issueTallyNo"
        show-overflow-tooltip
        sortable="custom"
        label="领料单号"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="issueTranDeptNo"
        show-overflow-tooltip
        sortable="custom"
        label="领料部门"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="issueTranEmpName"
        show-overflow-tooltip
        sortable="custom"
        label="领料人"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="issuetype"
        show-overflow-tooltip
        sortable="custom"
        label="领料类别"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="itemName"
        show-overflow-tooltip
        sortable="custom"
        label="物资类别第四级"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="kundAName"
        show-overflow-tooltip
        sortable="custom"
        label="物资类别第三级"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="kinName"
        show-overflow-tooltip
        sortable="custom"
        label="物资类别第二级"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="locDes"
        show-overflow-tooltip
        sortable="custom"
        label="仓位"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="matrlGrade"
        show-overflow-tooltip
        sortable="custom"
        label="品级"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="matrlNo"
        show-overflow-tooltip
        sortable="custom"
        label="物料编码"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="mm024ID"
        show-overflow-tooltip
        sortable="custom"
        label="单据id"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="oldMatrlno"
        show-overflow-tooltip
        sortable="custom"
        label="旧编码"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="overhaulNo"
        show-overflow-tooltip
        sortable="custom"
        label="年修项目编号"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="planUseCode"
        show-overflow-tooltip
        sortable="custom"
        label="计划用途"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="property"
        show-overflow-tooltip
        sortable="custom"
        label="领料属性"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="qty"
        show-overflow-tooltip
        sortable="custom"
        label="数量"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="rdNo"
        show-overflow-tooltip
        sortable="custom"
        label="研发项目编号"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="receiver"
        show-overflow-tooltip
        sortable="custom"
        label="领料人"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="remark"
        show-overflow-tooltip
        sortable="custom"
        label="备注"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="rissueTallyNo"
        show-overflow-tooltip
        sortable="custom"
        label="关联入库单号"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="tissueTallyNo"
        show-overflow-tooltip
        sortable="custom"
        label="关联退库单号"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="unit"
        show-overflow-tooltip
        sortable="custom"
        label="计量单位"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="unitPrice"
        show-overflow-tooltip
        sortable="custom"
        label="单价"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="vchrNo"
        show-overflow-tooltip
        sortable="custom"
        label="凭证号"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="venderId"
        show-overflow-tooltip
        sortable="custom"
        label="购货单位"
        width="140px">
      </el-table-column>
    <el-table-column
        prop="remarks"
        show-overflow-tooltip
        sortable="custom"
        label="备注信息"
        width="140px">
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        fixed="right"
        width="200"
        label="操作">
        <template  slot-scope="scope">
          <el-button v-if="hasPermission('spareparts:material:sparepartsErpBank:view')" type="text" icon="el-icon-view" size="small" @click="view(scope.row.id)">查看</el-button>
          <el-button v-if="hasPermission('spareparts:material:sparepartsErpBank:edit')" type="text" icon="el-icon-edit" size="small" @click="edit(scope.row.id)">修改</el-button>
          <el-button v-if="hasPermission('spareparts:material:sparepartsErpBank:del')" type="text"  icon="el-icon-delete" size="small" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageNo"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="total"
      background
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
        <!-- 弹窗, 新增 / 修改 -->
    <SparepartsErpBankForm  ref="sparepartsErpBankForm" @refreshDataList="refreshList"></SparepartsErpBankForm>
  </div>
</template>

<script>
  import SparepartsErpBankForm from './SparepartsErpBankForm'
  import axios from 'axios'
  export default {
    data () {
      return {
        name: '黑龙江钢铁',
        searchForm: {
          compId: '7ea8656af2d04318ada8aa225b57a2b7',
          finalDate: ''
        },
        dataList: [],
        pageNo: 1,
        pageSize: 10,
        total: 0,
        orderBy: '',
        dataListSelections: [],
        isSearchCollapse: true,
        isImportCollapse: false,
        loading: false
      }
    },
    components: {
      SparepartsErpBankForm
    },
    activated () {
      this.refreshList()
    },

    methods: {
      // 获取数据列表
      refreshList () {
        this.loading = true
        const instance = axios.create()
        instance({
          url: '/erp/jlerp/ms/MActionServlet/com.jl.ms.servlet.OtherSysServlet/getPickInfoData?Content-Type=application/json',
          method: 'get',
          params: {
            ...this.searchForm
          }
        }).then(({data}) => {
        console.log(data.pickInfoData)
        if (data.pickInfoData === undefined) {
          this.dataList = []
          this.loading = false
          this.total = 0
        } else {
        this.dataList = data.pickInfoData
        this.total = this.dataList.length
        // console.log("dataList.slice((this.pageNo - 1) * this.total, (this.pageNo - 1) * this.total + this.total)")
        // console.log(this.pageNo)
        // console.log(this.total)
        // console.log(this.dataList.slice((this.pageNo - 1) * this.total, (this.pageNo - 1) * this.total + this.total))
        this.loading = false
        }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageNo = 1
        this.refreshList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageNo = val
        this.refreshList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },

    // 排序
      sortChangeHandle (obj) {
        if (obj.order === 'ascending') {
          this.orderBy = obj.prop + ' asc'
        } else if (obj.order === 'descending') {
          this.orderBy = obj.prop + ' desc'
        } else {
          this.orderBy = ''
        }
        this.refreshList()
      },
      // 新增
      add () {
        this.$refs.sparepartsErpBankForm.init('add', '')
      },
      // 修改
      edit (id) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        this.$refs.sparepartsErpBankForm.init('edit', id)
      },
      // 查看
      view (id) {
        this.$refs.sparepartsErpBankForm.init('view', id)
      },
      // 删除
      del (id) {
        let ids = id || this.dataListSelections.map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.$http({
            url: '/spareparts/material/sparepartsErpBank/delete',
            method: 'delete',
            params: {'ids': ids}
          }).then(({data}) => {
            if (data && data.success) {
              this.$message.success(data.msg)
              this.refreshList()
            }
            this.loading = false
          })
        })
      },
      // 导入成功
      uploadSuccess (res, file) {
        if (res.success) {
          this.$message.success({dangerouslyUseHTMLString: true,
            message: res.msg})
        } else {
          this.$message.error(res.msg)
        }
      },
      // 下载模板
      downloadTpl () {
        this.$utils.download('/spareparts/material/sparepartsErpBank/import/template')
      },
      exportExcel () {
        this.$utils.download('/spareparts/material/sparepartsErpBank/export')
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.refreshList()
      }
    }
  }
</script>
